package com.yoke.service.domain;

import com.yoke.system.SystemBean;
import com.yoke.system.log.SystemLog;

import java.io.*;
import java.util.HashMap;

/**
 * Created by jiangzeyin on 2017/5/11.
 */
public abstract class DoMainBaseService {
    //protected static String bootPath;

    String getBootPath() {
        return SystemBean.getInstance().getEnvironment().getProperty("boot.conf");
    }


    private static final HashMap<String, String> DEFAULT_MAP = new HashMap<>();

    static {
        DEFAULT_MAP.put("format", "json");
        DEFAULT_MAP.put("login_token", "30576,8659221fa98286ada86336cc005a4b27");
    }

    HashMap<String, String> getDefault() {
        return clone(DEFAULT_MAP);
    }

    private static <T extends Serializable> T clone(T obj) {
        T clonedObj = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            oos.close();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            clonedObj = (T) ois.readObject();
            ois.close();
        } catch (Exception e) {
            SystemLog.ERROR().error("复制对象错误", e);
        }
        return clonedObj;

    }
}
